<template>
  <div class="board-column">
    <div class="board-column-header">
      {{ headerText }}
      <el-button style="float:right; margin-top: 5px; background: transparent; border: transparent;" @click="handleSave">
        <i style="color:red;" class="el-icon-edit" />
      </el-button>
    </div>
    <draggable
      :list="list"
      v-bind="$attrs"
      :set-data="setData"
      class="board-column-content"
      @change="updateData"
    >
      <div v-for="(element,index) in list" :key="element.index" class="board-item">
        <el-tag style="float:left" type="danger">
          {{ index }}
        </el-tag>
        <span v-if="deleteEnable" style="float: right ;" @click="deleteEle(index)">
          <i style="color:#ff4949" class="el-icon-delete" />
        </span>
        <p v-if="element.number !== '-999'" align="center"> {{ element.number }}  {{ element.name }} </p>
        <div v-if="element.number!== '-999'" style="margin-top: 20px;" align="center">
          <i style="color:blue," class="el-icon-bottom" />
        </div>
      </div>
    </draggable>
    <draggable
      :list="list2"
      v-bind="$attrs"
      :set-data="setData2"
      class="board-column-content"
      @change="updateData2"
    >
      <div v-for="(element,index) in list2" :key="element.index" class="board-item">
        <el-tag style="float:left" type="danger">
          {{ index }}
        </el-tag>
        <span v-if="deleteEnable" style="float: right ;" @click="deleteEle2(index)">
          <i style="color:#ff4949" class="el-icon-delete" />
        </span>
        <p v-if="element.number !== '-999'" align="center"> {{ element.number }}  {{ element.name }} </p>
      </div>
    </draggable>
  </div>
</template>

<script>
import draggable from 'vuedraggable'

export default {
  name: 'KanbanTwoLabel',
  components: {
    draggable
  },
  props: {
    headerText: {
      type: String,
      default: 'Header'
    },
    options: {
      type: Object,
      default() {
        return {}
      }
    },
    list: {
      type: Array,
      default() {
        return []
      }
    },
    list2: {
      type: Array,
      default() {
        return []
      }
    },
    deleteEnable: {
      type: Boolean,
      default() {
        return false
      }
    }
  },
  methods: {
    setData(dataTransfer) {
      // to avoid Firefox bug
      // Detail see : https://github.com/RubaXa/Sortable/issues/1012
      dataTransfer.setData('Text', '')
    },
    updateData() {
      this.$emit('updateData')
    },
    deleteEle(index) {
      this.list.splice(index, 1)
    },
    setData2(dataTransfer) {
      // to avoid Firefox bug
      // Detail see : https://github.com/RubaXa/Sortable/issues/1012
      dataTransfer.setData('Text', '')
    },
    updateData2() {
      this.$emit('updateData2')
    },
    deleteEle2(index) {
      this.list2.splice(index, 1)
    },
    handleSave() {
      this.$emit('save')
    }
  }
}
</script>
<style lang="scss" scoped>
.board-column {
  min-width: 150px;
  min-height: 50px;
  height: auto;
  overflow: hidden;
  background: #f0f0f0;
  border-radius: 5px;

  .board-column-header {
    height: 50px;
    line-height: 50px;
    overflow: hidden;
    padding: 0 20px;
    text-align: center;
    background: #333;
    color: #fff;
    border-radius: 3px 3px 0 0;
  }
  .board-column-content {
    float:left;
    width:50%;
    height: auto;
    overflow: hidden;
    border: 10px solid transparent;
    min-height: 60px;
    display: flex;
    justify-content: flex-start;
    flex-direction: column;
    align-items: center;
    .board-item {
      cursor: pointer;
      width: 100%;
      height: 60px;
      margin: 10px;
      background-color: rgb(96, 199, 233);
      text-align: left;
      line-height: 20px;
      padding: 5px 5px;
      box-sizing: border-box;
      border-radius: 10px;
      box-shadow: 0px 1px 3px 0 rgba(0, 0, 0, 0.2);
    }
  }
}
</style>

